from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


class CompareIndexT(db.Model):
    __tablename__ = 'compare_index_t'
    __table_args__ = (
        db.Index('uk_compare_index_1', 'source', 'tablename', 'indexname', 'schema'),
    )

    id = db.Column(db.BigInteger, primary_key=True, server_default=db.FetchedValue())
    source = db.Column(db.String(500), nullable=False)
    tablename = db.Column(db.String(64), nullable=False)
    indexname = db.Column(db.String(64))
    indexdef = db.Column(db.String(4000))
    index_is_primary = db.Column(db.String(1))
    index_is_unique = db.Column(db.String(1))
    index_columns = db.Column(db.String(3000))
    where_condition = db.Column(db.String(2000))
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    schema = db.Column(db.String(255))


class ComparePriv(db.Model):
    __tablename__ = 'compare_privs'

    id = db.Column(db.BigInteger, primary_key=True, server_default=db.FetchedValue())
    source = db.Column(db.String)
    schema = db.Column(db.String)
    owner = db.Column(db.String)
    object_name = db.Column(db.String)
    type = db.Column(db.String)
    grantor = db.Column(db.String)
    grantee = db.Column(db.String)
    privilege = db.Column(db.String)
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())


class CompareProc(db.Model):
    __tablename__ = 'compare_proc'

    id = db.Column(db.Integer, primary_key=True, server_default=db.FetchedValue())
    source = db.Column(db.String(500))
    schema = db.Column(db.String(500))
    pro_name = db.Column(db.String(500))
    pro_arg = db.Column(db.String(5000))
    pro_arg_type = db.Column(db.String(5000))
    pro_ret_type = db.Column(db.String(5000))
    prosrc = db.Column(db.Text)
    pro_content = db.Column(db.Text)
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    owner = db.Column(db.String)


class CompareSequence(db.Model):
    __tablename__ = 'compare_sequence'

    id = db.Column(db.BigInteger, primary_key=True, server_default=db.FetchedValue())
    source = db.Column(db.String)
    owner = db.Column(db.String)
    schema = db.Column(db.String)
    sequence_name = db.Column(db.String)
    min_value = db.Column(db.String)
    max_value = db.Column(db.String)
    increment_by = db.Column(db.String)
    cache_size = db.Column(db.String)
    cycle_flag = db.Column(db.String)
    last_number = db.Column(db.String)
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())


class CompareSequenceT(db.Model):
    __tablename__ = 'compare_sequence_t'
    __table_args__ = (
        db.Index('uk_compare_sequence_1', 'source', 'sequencename', 'schema'),
    )

    id = db.Column(db.BigInteger, primary_key=True, server_default=db.FetchedValue())
    source = db.Column(db.String(500), nullable=False)
    sequencename = db.Column(db.String(64))
    sequence_value_check_result = db.Column(db.String(1))
    repair_scripts = db.Column(db.String(4000))
    last_value = db.Column(db.String(64))
    pkey_max_value = db.Column(db.String(64))
    increment_by = db.Column(db.String(64))
    sequence_like_table = db.Column(db.String(64))
    related_table_name = db.Column(db.String(64))
    column_name = db.Column(db.String(64))
    pkey = db.Column(db.String(1))
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    schema = db.Column(db.String(255))


# OK 已mapping
class CompareTable(db.Model):
    __tablename__ = 'compare_table'
    id = db.Column(db.Integer, primary_key=True, server_default=db.FetchedValue())
    source = db.Column(db.String(500))
    schema = db.Column(db.String(500))
    table_name = db.Column(db.String(500))
    table_comment = db.Column(db.String(4000))
    column_name = db.Column(db.String(500))
    data_type = db.Column(db.String(500))
    data_length = db.Column(db.String(500))
    data_default = db.Column(db.String(500))
    nullable = db.Column(db.String(500))
    pkey = db.Column(db.String(500))
    column_comment = db.Column(db.String(4000))
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())


class CompareTableJobResultT(db.Model):
    __tablename__ = 'compare_table_job_result_t'

    id = db.Column(db.BigInteger, primary_key=True, server_default=db.FetchedValue())
    task_id = db.Column(db.Integer, index=True)
    total_check_result = db.Column(db.String)
    schema = db.Column(db.String(500))
    table_name = db.Column(db.String(500))
    column_name = db.Column(db.String(500))
    column_name_check_result = db.Column(db.String)
    s1 = db.Column(db.String)
    s2 = db.Column(db.String)
    s3 = db.Column(db.String)
    s4 = db.Column(db.String)
    s5 = db.Column(db.String)
    s6 = db.Column(db.String)
    s7 = db.Column(db.String)
    data_type_result = db.Column(db.String)
    data_type1 = db.Column(db.String(500))
    data_type2 = db.Column(db.String(500))
    data_type3 = db.Column(db.String(500))
    data_type4 = db.Column(db.String(500))
    data_type5 = db.Column(db.String(500))
    data_type6 = db.Column(db.String(500))
    data_type7 = db.Column(db.String(500))
    nullable_result = db.Column(db.String)
    nullable1 = db.Column(db.String)
    nullable2 = db.Column(db.String)
    nullable3 = db.Column(db.String)
    nullable4 = db.Column(db.String)
    nullable5 = db.Column(db.String)
    nullable6 = db.Column(db.String)
    nullable7 = db.Column(db.String)
    pkey_result = db.Column(db.String)
    pkey1 = db.Column(db.String)
    pkey2 = db.Column(db.String)
    pkey3 = db.Column(db.String)
    pkey4 = db.Column(db.String)
    pkey5 = db.Column(db.String)
    pkey6 = db.Column(db.String)
    pkey7 = db.Column(db.String)
    data_default_result = db.Column(db.String)
    data_default1 = db.Column(db.String)
    data_default2 = db.Column(db.String)
    data_default3 = db.Column(db.String)
    data_default4 = db.Column(db.String)
    data_default5 = db.Column(db.String)
    data_default6 = db.Column(db.String)
    data_default7 = db.Column(db.String)
    table_comment_result = db.Column(db.String)
    table_comment1 = db.Column(db.String)
    table_comment2 = db.Column(db.String)
    table_comment3 = db.Column(db.String)
    table_comment4 = db.Column(db.String)
    table_comment5 = db.Column(db.String)
    table_comment6 = db.Column(db.String)
    table_comment7 = db.Column(db.String)
    column_comment_result = db.Column(db.String)
    column_comment1 = db.Column(db.String)
    column_comment2 = db.Column(db.String)
    column_comment3 = db.Column(db.String)
    column_comment4 = db.Column(db.String)
    column_comment5 = db.Column(db.String)
    column_comment6 = db.Column(db.String)
    column_comment7 = db.Column(db.String)
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())


class CompareTaskT(db.Model):
    __tablename__ = 'compare_task_t'

    task_id = db.Column(db.BigInteger, primary_key=True, server_default=db.FetchedValue())
    task_name = db.Column(db.String(300))
    db_cfg_1_id = db.Column(db.BigInteger)
    db_cfg_2_id = db.Column(db.BigInteger)
    db_cfg_3_id = db.Column(db.BigInteger)
    db_cfg_4_id = db.Column(db.BigInteger)
    db_cfg_5_id = db.Column(db.BigInteger)
    db_cfg_6_id = db.Column(db.BigInteger)
    db_cfg_7_id = db.Column(db.BigInteger)
    created_by = db.Column(db.BigInteger, nullable=False, server_default=db.FetchedValue())
    creation_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    last_updated_by = db.Column(db.BigInteger, nullable=False, server_default=db.FetchedValue())
    last_update_date = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    description = db.Column(db.String(500))
